home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-24 | 7.0 KB | 322 lines | [TEXT/CWIE] |
- // CLGCommander.cp
- //
- // ScriptExplorer Commander-in-Chief
- //
- // May be distributed freely
- // Brian Hamlin, NoEsis software contruction nsc@screenlight.com
- //****************************************************************************
-
- // system headers
- #ifndef __ICONS__
- # include <Icons.h>
- #endif
- #ifndef __RESOURCES__
- # include <Resources.h>
- #endif
-
- #include <Files.h>
- #include <Folders.h>
- #include <Script.h>
- #include <TextUtils.h>
-
- //#include <ansi_parms.h>
- //#define __dest_os __mac_os
- //include <string.h>
-
- // PowerPlant headers
- #include <UDesktop.h>
- #include <LWindow.h>
-
- // project headers
- #include "LG_Constants.h"
- #include "CLGCommander.h"
- #include "CLG_CharsGrid.h"
- #include "CLG_CharInfo.h"
-
-
-
- //***********************
- // CLGCommander
- //****************************************************************************
-
- CLGCommander::CLGCommander(LCommander *inSuperCommander)
- : LCommander(inSuperCommander)
- {
- mWindow = NULL;
-
- return;
- }
-
-
- //***********************
- // ~CLGCommander
- //****************************************************************************
- CLGCommander::~CLGCommander(void)
- {
- delete mWindow;
- }
-
-
- //***********************
- // ~CLGCommander
- //
- // Create a new PPD Window using an FSSpec as a reference.
- //****************************************************************************
- OSErr CLGCommander::CreateWindow()
- {
-
- // preliminaries
-
- // create window
- mWindow = LWindow::CreateWindow( 1, this);
- mWindow->Show();
- mWindow->SetSuperCommander( this);
- //GetIndString(theWindowTitle, STRS_WindowNames, 1);
- //NumToString(mNextQuery++, theWindowNumber);
- //LString::AppendPStr(theWindowTitle, theWindowNumber);
- //mWindow->SetDescriptor(theWindowTitle);
-
-
- // Text
- mCharsGrid = (CLG_CharsGrid *) mWindow->FindPaneByID( PID_CharsGrid);
- mCharInfo = (CLG_CharInfo *) mWindow->FindPaneByID( PID_PnCharInfo);
-
- mMenuDrawAction = (LStdPopupMenu*) mWindow->FindPaneByID( PID_MenuDrawAct);
- mMenuScriptAction = (LStdPopupMenu*) mWindow->FindPaneByID( PID_MenuScriptAct);
-
- mMenuDrawAction->Hide();
-
- mBtnUp = (LButton*)mWindow->FindPaneByID( PID_IBtnPgUp);
- mBtnDown = (LButton*)mWindow->FindPaneByID( PID_IBtnPgDown);
-
- AllowPaging( false);
-
- UReanimator::LinkListenerToControls( this, mWindow, 1);
- mWindow->Show();
-
- this->StartIdling();
-
- return noErr;
- }
-
-
- //***********************
- // ListenToMessage
- //
- // Respond to messages from Broadcasters
- //****************************************************************************
- void
- CLGCommander::ListenToMessage(
- MessageT inMessage,
- void *ioParam)
- {
- switch ( inMessage) {
-
- default:
- // CONVENTION - Just pass the msg to the Cmd Heirarchy
- ObeyCommand( inMessage, ioParam);
- break;
- };
-
- return;
- }
-
-
- //***********************
- // ObeyCommand
- //
- // Respond to messages from Broadcasters
- //****************************************************************************
- Boolean CLGCommander::ObeyCommand(CommandT inCommand, void *ioParam)
- {
- Boolean cmdHandled = true;
-
- switch (inCommand)
- {
-
- case cmd_MenuScriptAct:
- DoScriptActMenu();
- break;
-
- case cmd_SomeBtn:
- ObeyCommand( cmd_About, 0);
- break;
-
- case cmd_PageUp:
- mCharsGrid->DoPageUp();
- mCharInfo->SetBaseCharDisp( mCharsGrid->mBaseChar);
- break;
-
- case cmd_PageDown:
- mCharsGrid->DoPageDown();
- mCharInfo->SetBaseCharDisp( mCharsGrid->mBaseChar);
- break;
-
- default:
- cmdHandled = LCommander::ObeyCommand(inCommand, ioParam);
- break;
- }
-
- return cmdHandled;
- }
-
-
-
- //***********************
- // SpendTime
- //****************************************************************************
- void
- CLGCommander::SpendTime(
- const EventRecord& inMacEvent)
- {
- long scripNum;
- Boolean isDblByteScript;
-
- // Check Current Script System
- scripNum = GetScriptManagerVariable( smKeyScript);
-
- if ( mCurScriptNum != scripNum ) {
- // FontToScript( mCharsGrid->mFontNum) != scripNum
- mCharsGrid->mFontNum = GetScriptVariable( scripNum, smScriptAppFond);
- mCharsGrid->mFontSiz = 0x00FF & GetScriptManagerVariable( smScriptMonoFondSize);
-
- isDblByteScript = ( scripNum == smJapanese
- || scripNum == smTradChinese
- || scripNum == smSimpChinese
- || scripNum == smKorean );
-
- AllowPaging( isDblByteScript);
-
- if ( !isDblByteScript) {
- mCharsGrid->mBaseChar = 0;
- mCharInfo->SetBaseCharDisp( 0);
- }
-
- // Keep a copy of the curScriptNum both here (for easy access)
- // and in the CharGrid, so it can handle the paging/drawing correctly
- // This is the only place scriptNum is changed, so synch is no problem
-
- mCurScriptNum = scripNum;
- mCharsGrid->mCurScriptNum = scripNum;
- mCharsGrid->Refresh();
- }
-
- // Onward - update the Char info based on the Mouse Position
- // Check for mousePos in Grid Area
- Rect tR = {0,0,20,20};
- Point tGridLoc;
- Point portMouse = inMacEvent.where;
- SPoint32 gridLoc;
-
- mWindow->GlobalToPortPoint(portMouse);
- if ( mWindow->FindSubPaneHitBy( portMouse.h, portMouse.v) == mCharsGrid) {
- // find the char the cursor is over
-
- mCharsGrid->GetFrameLocation( gridLoc);
- portMouse.h -= gridLoc.h + kcgHOffset;
- tGridLoc.h = portMouse.h/kcgHSpacing;
-
- portMouse.v -= gridLoc.v + kcgVOffset;
- tGridLoc.v = portMouse.v/kcgVSpacing;
-
- if ( tGridLoc.v < 16 && tGridLoc.h < 16) {
- if ( mLastCGChar.v != tGridLoc.v || mLastCGChar.h != tGridLoc.h) {
- mLastCGChar = tGridLoc;
- mCharInfo->SetCharNum(
- ((mCharsGrid->mBaseChar)*256) + 16*tGridLoc.v + tGridLoc.h);
- }
- }
-
- }
-
- return;
- }
-
-
- //***********************
- // AllowPaging
- //****************************************************************************
- void
- CLGCommander::AllowPaging( Boolean inFlag)
- {
- if ( !inFlag) {
- mBtnUp->SetGraphics( 1018, 1018);
- mBtnDown->SetGraphics( 1019, 1019);
-
- mBtnUp->Disable();
- mBtnDown->Disable();
-
- } else {
- mBtnUp->SetGraphics( PID_IBtnPgUp, PID_IBtnPgUp+1);
- mBtnDown->SetGraphics( PID_IBtnPgDown, PID_IBtnPgDown+1);
-
- mBtnUp->Enable();
- mBtnDown->Enable();
- }
-
- mBtnUp->Refresh();
- mBtnDown->Refresh();
-
- return;
- }
-
-
- //***********************
- // DoScriptActMenu
- //****************************************************************************
- void
- CLGCommander::DoScriptActMenu()
- {
- mCharsGrid->mScriptAction = mMenuScriptAction->GetValue();
- mCharsGrid->DoChangeChars();
- return;
- }
-
-
- //***********************
- // FindCommandStatus
- //****************************************************************************
- void CLGCommander::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
- outUsesMark = false;
-
- switch (inCommand)
- {
- case cmd_New:
- outEnabled = false;
- break;
-
- case cmd_Close:
- outEnabled = false;
- //if (mWindow != NULL)
- // outEnabled = true;
- break;
-
-
- default:
- LCommander::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- }
- }
-
-
- //***********************
- // AllowSubRemoval
- //****************************************************************************
- Boolean CLGCommander::AllowSubRemoval(LCommander *inSub)
- {
- return (true);
- }
-
-
- //***************************************************************************************
- // E N D O F L I S T I N G
-
-
-